<%-- 
    Document   : authData
    Created on : 2016-7-21, 17:55:16
    Author     : 52461
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="../../link.jsp"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body ng-app="auth" style="font-family: 微软雅黑;padding-top: 10px;" ng-controller="mainCtrl">

        <div class="col-lg-12">
            <div class="panel panel-default ">
                <div class=" panel-heading">
                    <strong><span class="glyphicon glyphicon-th"></span>权限管理</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <button ng-click="showCreate()" class="btn m-b-xs btn-sm btn-success btn-addon" ng-click="saveInfo()"><i class="fa fa-plus"></i>添加</button>
                    <!--                    <button  class="btn btn-primary btn-r btn-fab"><i class="mdi mdi-plus"></i></button>-->

                    <!--<div style="clear: both"></div>-->
                </div>
                <table class="table">
                    <tr>
                        <th>序号</th> 
                        <th>名称</th> 
                        <th>URL</th> 
                        <th>描述</th> 
                        <th>样式</th> 
                        <th>类型</th>
                        <th>其他</th>
                    </tr>
                    <tr ng-repeat="item in list">
                        <td>{{$index}}</td>
                        <td>{{item.name}}</td>
                        <td>{{item.url}}</td>
                        <td>{{item.des}}</td>
                        <td>{{item.icon_class}}</td>

                        <td>{{(item.type==1?"权限":"菜单")+""}}</td>
                        <td>
                            <button ng-click="editAuth(item)" ng-click="editRole(list)" class="btn btn-success btn-xs"><span class="fa fa-edit"></span>&nbsp;修改</button>
                            <button ng-click="deleteAuth(item)" class="btn btn-danger btn-xs"><span class="fa fa-bolt"></span>&nbsp;删除</button>
                        </td>
                    </tr>
                </table>
            </div>

        </div>

        <div class="modal fade mode-x" role="dialog" aria-labelledby="gridSystemModalLabel">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="gridSystemModalLabel">{{modalTitle}}</h4>
                    </div>
                    <div class="modal-body">
                        <form  name="users" id="users" onsubmit="return false;">
                            <table style="width: 100%" class="cx-table">
                                <tr>
                                    <td>菜单</td>
                                    <td>
                                        <select ng-model="data.parent_pk" type="text" class="form-control">
                                            <option value="{{menu.pk}}" ng-repeat="menu in menus">{{menu.name}}</option>
                                        </select>
                                    </td>

                                </tr>
                                <tr>
                                    <td>名称</td>
                                    <td>
                                        <input ng-model="data.name" type="text" class="form-control" required="">
                                    </td>

                                </tr>
                                <tr>
                                    <td>URL</td>
                                    <td>
                                        <input ng-model="data.url" type="text" class="form-control" required="">
                                    </td>

                                </tr>
                                <tr>
                                    <td>描述</td>
                                    <td>
                                        <input ng-model="data.des" type="text" class="form-control">
                                    </td>

                                </tr>
                                <tr>
                                    <td>样式</td>
                                    <td>
                                        <input ng-model="data.icon_class" type="text" class="form-control">
                                    </td>

                                </tr>
                                <tr>
                                    <td>类型</td>
                                    <td>
                                        <select class="form-control" ng-model="data.type" required="">
                                            <option value="0">菜单</option>
                                            <option value="1">权限</option>
                                        </select>
                                        <!--                                        <input ng-model="data.type" type="text" class="form-control">-->
                                    </td>
                                </tr>


                            </table>
                        </form>

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button  ng-click="saveInfo()" ng-disabled="users.$invalid" type="button" class="btn btn-primary"><span class="fa fa-save"></span>&nbsp;&nbsp;保存</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->
    </body>
</html>
<script>

    angular.module("auth", ['baseModule'])
            .controller("mainCtrl", function ($scope, base) {
                $scope.modalTitle = "添加权限";
                $scope.data = {};
                $scope.data.type = "1";
                $scope.showCreate = function () {
                    $scope.data = {};
                    $(".mode-x").modal('show');
                }

                $scope.saveInfo = function () {
                    base.post("saveAuth", $scope.data).get(function (data) {
                        if (data == "true") {
                            steveAl("保存成功", 1000);
                            $(".mode-x").modal('hide');
                            $scope.getList();
                        } else {
                            steveAl("保存失败", 1000);
                        }
                    });
                }


                $scope.getList = function () {
                    base.post("getAuth").get(function (data) {
                        console.log(data);
                        if (data) {
                            $scope.list = data;

                        }

                    })
                };
                $scope.getMenu = function () {
                    base.post("getMenu").get(function (data) {
                        console.log(data);
                        $scope.menus = data;
                    })
                }
                $scope.deleteAuth = function (item) {
                    steveConfrim("确定删除吗？", function () {
                        base.post("deleteAuth", {pk: item.pk}).get(function (data) {
                            if (data == "true") {
                                steveAl("删除成功", 1000);
                            } else {
                                steveAl("删除失败", 1000);
                            }
                        })
                    })
                }
                $scope.editAuth = function (item) {
                 
                    $scope.data = item;
                       console.log( $scope.data);
                    $(".mode-x").modal('show');
                }
                var init = function () {
                    $scope.getList();
                    $scope.getMenu();

                }
                init();

            })

</script>
